<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>月度工作考核</title>
    <link rel="stylesheet" href="../css/all.min.css">
    <style>
        body {
            font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
            margin: 0;
            padding: 0;
            line-height: 1.6;
            background-color: #fff;
            color: #333;
        }
        
        .container {
            width: 21cm;
            padding: 2cm;
            margin: 0 auto;
            box-sizing: border-box;
            background-color: white;
            box-shadow: 0 0 15px rgba(0,0,0,0.1);
            position: relative;
        }
        
        .header {
            margin-bottom: 25px;
            border-bottom: 2px solid #5d478b;
            position: relative;
        }
        
        .report-title {
            display: flex;
            font-size: 22px;
            font-weight: bold;
            color: #5d478b;
            text-align: center;
            letter-spacing: 1px;
            position: relative;
            padding-bottom: 10px;
            justify-content: center;
        }
        
        
        .employee-card {
            background: linear-gradient(135deg, #f5f3fa 0%, #f0ebf8 100%);
            border-radius: 8px;
            padding: 15px 20px;
            margin: 0 auto 25px;
            box-shadow: 0 3px 10px rgba(93, 71, 139, 0.1);
            border: 1px solid #e1d8f0;
            display: flex;
            flex-wrap: wrap;
            justify-content: space-around;
            gap: 20px 40px;
        }
        
        .info-item {
            display: flex;
            align-items: center;
            font-size: 15px;
            color: #555;
        }
        
        .info-label {
            font-weight: 600;
            color: #5d478b;
            margin-right: 8px;
            display: flex;
            align-items: center;
        }
        
        .info-label .fas {
            margin-right: 6px;
            font-size: 14px;
            color: #7e57c2;
            width: 16px;
            text-align: center;
        }
        
        .info-value {
            font-weight: 500;
            padding: 5px 10px;
            border-radius: 4px;
            background-color: white;
            border: 1px solid #e0e0e0;
            min-width: 150px;
            transition: all 0.3s;
        }
        
        .info-value:focus {
            border-color: #9c27b0;
            box-shadow: 0 0 0 2px rgba(156, 39, 176, 0.2);
            outline: none;
        }
        
        table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 30px;
            font-size: 14px;
            box-shadow: 0 2px 5px rgba(0,0,0,0.05);
        }
        
        th, td {
            padding: 12px 10px;
            text-align: center;
            border: 1px solid #e0e0e0;
        }
        
        th {
            background-color: #f5f3fa;
            font-weight: 600;
            color: #5d478b;
            border-bottom: 2px solid #d1c4e9;
            text-align: center;
        }
        
        .editable {
            min-height: 22px;
            outline: none;
            display: block;
            padding: 2px 5px;
            border-radius: 3px;
            transition: all 0.2s;
        }
        
        .editable:focus {
            background-color: #f0e8ff;
            box-shadow: 0 0 0 2px rgba(93, 71, 139, 0.2);
        }
        
        .signature-box {
            position: relative;
            border: 1px solid #e0e0e0;
            padding: 10px;
            margin-top: 10px;
        }
        
        .signature-title {
            font-size: 15px;
            margin-bottom: 8px;
            color: #555;
        }
        
        .signature-line {
            height: 1px;
            background-size: 10px 1px;
            margin-top: 20px;
        }
        
        .signature-date {
            text-align: right;
            margin-top: 10px;
            color: #666;
            font-size: 14px;
        }
        
        .note {
            font-size: 13px;
            color: #777;
            line-height: 1.8;
            margin-top: 5px;
        }
        
        .controls {
            position: fixed;
            right: 30px;
            top: 50%;
            transform: translateY(-50%);
            display: flex;
            flex-direction: column;
            gap: 12px;
            z-index: 100;
        }
        
        button {
            padding: 10px 20px;
            cursor: pointer;
            border: none;
            border-radius: 25px;
            color: white;
            font-weight: bold;
            background: linear-gradient(135deg, #7e57c2 0%, #5d478b 100%);
            box-shadow: 0 3px 8px rgba(93, 71, 139, 0.3);
            transition: all 0.3s ease;
            font-size: 14px;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        
        button:hover {
            background: linear-gradient(135deg, #5d478b 0%, #452b7a 100%);
            box-shadow: 0 5px 12px rgba(93, 71, 139, 0.4);
            transform: translateY(-2px) scale(1.02);
        }
        
        button .fas {
            margin-right: 8px;
        }
        
        .total-row {
            font-weight: bold;
            background-color: #f5f3fa;
        }
        
        .total-row td {
            border-top: 2px solid #d1c4e9;
            color: #5d478b;
        }
        
        @media (max-width: 768px) {
            .container {
                width: auto;
                padding: 1.5cm;
            }
            
            .controls {
                right: 15px;
                flex-direction: row;
                flex-wrap: wrap;
                top: auto;
                bottom: 20px;
                transform: none;
                justify-content: flex-end;
            }
            
            button {
                padding: 8px 15px;
                font-size: 13px;
            }
            
            .employee-card {
                flex-direction: column;
                gap: 12px;
                padding: 15px;
            }
            
            .info-item {
                width: 100%;
            }
        }
        
        @media print {
            .no-print {
                display: none;
            }
            body {
                background: none;
            }
            .container {
                padding: 0;
                width: auto;
                margin: 10px;
                box-shadow: none;
            }
            button {
                display: none;
            }
        }
    </style>
</head>
<body>
    <div class="controls no-print">
        <button onclick="addRow()"><i class="fas fa-plus-circle"></i>增加行</button>
        <button onclick="removeRow()"><i class="fas fa-minus-circle"></i>删除行</button>
        <button onclick="calculateTotal()"><i class="fas fa-calculator"></i>计算总分</button>
        <button onclick="window.print()"><i class="fas fa-print"></i>打印表格</button>
    </div>
    
    <div class="container">
        <div class="header">
            <div class="report-title">月度工作考核（<span class="editable" contenteditable="true" id="year-month">XX年XX月</span>）</div>
            
            <!-- 简化后的员工信息区域 -->
            <div class="employee-card">
                <div class="info-item">
                    <span class="info-label"><i class="fas fa-user-alt"></i>姓名：</span>
                    <span class="info-value" id="employee-name" contenteditable="true"></span>
                </div>
                <div class="info-item">
                    <span class="info-label"><i class="fas fa-mobile-alt"></i>电话：</span>
                    <span class="info-value" id="employee-phone" contenteditable="true"></span>
                </div>
            </div>
        </div>
        
        <table id="work-report">
            <thead>
                <tr>
                    <th width="10%">序号</th>
                    <th width="18%">工作类型</th>
                    <th width="30%">工作内容</th>
                    <th width="15%">权重（%）</th>
                    <th width="15%">评分（分）</th>
                    <th width="12%">备注</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>1</td>
                    <td><div class="editable" contenteditable="true"></div></td>
                    <td style="text-align: left;"><div class="editable" contenteditable="true"></div></td>
                    <td><div class="editable weight" contenteditable="true"></div></td>
                    <td><div class="editable score" contenteditable="true"></div></td>
                    <td><div class="editable" contenteditable="true"></div></td>
                </tr>
                <tr>
                    <td>2</td>
                    <td><div class="editable" contenteditable="true"></div></td>
                    <td style="text-align: left;"><div class="editable" contenteditable="true"></div></td>
                    <td><div class="editable weight" contenteditable="true"></div></td>
                    <td><div class="editable score" contenteditable="true"></div></td>
                    <td><div class="editable" contenteditable="true"></div></td>
                </tr>
                <tr>
                    <td>3</td>
                    <td><div class="editable" contenteditable="true"></div></td>
                    <td style="text-align: left;"><div class="editable" contenteditable="true"></div></td>
                    <td><div class="editable weight" contenteditable="true"></div></td>
                    <td><div class="editable score" contenteditable="true"></div></td>
                    <td><div class="editable" contenteditable="true"></div></td>
                </tr>
                <tr>
                    <td>4</td>
                    <td><div class="editable" contenteditable="true"></div></td>
                    <td style="text-align: left;"><div class="editable" contenteditable="true"></div></td>
                    <td><div class="editable weight" contenteditable="true"></div></td>
                    <td><div class="editable score" contenteditable="true"></div></td>
                    <td><div class="editable" contenteditable="true"></div></td>
                </tr>
                <tr>
                    <td>5</td>
                    <td><div class="editable" contenteditable="true"></div></td>
                    <td style="text-align: left;"><div class="editable" contenteditable="true"></div></td>
                    <td><div class="editable weight" contenteditable="true"></div></td>
                    <td><div class="editable score" contenteditable="true"></div></td>
                    <td><div class="editable" contenteditable="true"></div></td>
                </tr>
            </tbody>
            <tfoot>
                <tr class="total-row">
                    <td colspan="3">月度评分</td>
                    <td id="total-weight"></td>
                    <td id="total-score"></td>
                    <td></td>
                </tr>
            </tfoot>
        </table>
        
        <div class="signature">
            <div class="signature-box">
                <div class="signature-title"><i class="fas fa-signature"></i> 本人确认（签字）：</div>
                <div class="signature-line"></div>
                <div class="signature-date">年&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;月&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;日</div>
            </div>
            
            <div class="signature-box">
                <div class="signature-title"><i class="fas fa-user-tie"></i> 项目/业务负责人（签字）：</div>
                <div class="signature-line"></div>
                <div class="signature-date">年&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;月&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;日</div>
            </div>
        </div>
        
        <div class="note">
            <strong><i class="fas fa-info-circle"></i> 说明：</strong><br>
            1. 本考核表用于员工月度工作表现的评估，由员工本人填写工作内容，项目/业务负责人进行评分。<br>
            2. 工作类型可分为：日常工作、项目工作、临时任务、团队协作等，可根据实际情况填写。<br>
            3. 权重总和必须为100%，各项权重由项目/业务负责人根据工作重要性和工作量分配。<br>
            4. 评分标准：0-59分（不合格），60-69分（基本合格），70-79分（合格），80-89分（良好），90-100分（优秀）。<br>
            5. 月度评分计算公式：各项得分乘以相应权重后的总和。<br>
            6. 评分完成后，需员工本人和项目/业务负责人双方签字确认，以确保评估结果的公正性和准确性。
        </div>
    </div>

    <script>
        // 增加行
        function addRow() {
            const table = document.querySelector('#work-report tbody');
            const rowCount = table.rows.length + 1;
            const newRow = table.insertRow();
            
            newRow.innerHTML = `
                <td>${rowCount}</td>
                <td><div class="editable" contenteditable="true"></div></td>
                <td style="text-align: left;"><div class="editable" contenteditable="true"></div></td>
                <td><div class="editable weight" contenteditable="true"></div></td>
                <td><div class="editable score" contenteditable="true"></div></td>
                <td><div class="editable" contenteditable="true"></div></td>
            `;
            
            // 添加动画效果
            newRow.style.opacity = 0;
            let opacity = 0;
            const fadeIn = setInterval(() => {
                opacity += 0.1;
                newRow.style.opacity = opacity;
                if (opacity >= 1) clearInterval(fadeIn);
            }, 30);
        }
        
        // 删除行
        function removeRow() {
            const table = document.querySelector('#work-report tbody');
            if (table.rows.length > 1) {
                const row = table.rows[table.rows.length - 1];
                
                // 添加动画效果
                let opacity = 1;
                const fadeOut = setInterval(() => {
                    opacity -= 0.1;
                    row.style.opacity = opacity;
                    if (opacity <= 0) {
                        clearInterval(fadeOut);
                        row.remove();
                        // 重新编号
                        const rows = table.querySelectorAll('tr');
                        rows.forEach((row, index) => {
                            row.cells[0].textContent = index + 1;
                        });
                    }
                }, 30);
            } else {
                alert("至少保留一行数据！");
            }
        }
        
        // 计算总分
        function calculateTotal() {
            const weights = document.querySelectorAll('.weight');
            const scores = document.querySelectorAll('.score');
            
            let totalWeight = 0;
            let weightedScore = 0;
            let hasError = false;
            
            weights.forEach((weightEl, index) => {
                const weightText = weightEl.textContent.trim();
                const scoreText = scores[index].textContent.trim();
                
                // 提取权重百分比
                const weight = parseFloat(weightText) || 0;
                const score = parseFloat(scoreText) || 0;
                
                if (isNaN(weight)) {
                    alert(`第${index + 1}行的权重格式不正确，请输入数字`);
                    hasError = true;
                    return;
                }
                
                if (score < 0 || score > 100) {
                    alert(`第${index + 1}行的评分应在0-100之间`);
                    hasError = true;
                    return;
                }
                
                totalWeight += weight;
                weightedScore += score * (weight / 100);
            });
            
            if (hasError) return;
            
            // 检查权重总和是否为100%
            if (Math.abs(totalWeight - 100) > 0.0001) {
                alert(`权重总和应为100%，当前为${totalWeight.toFixed(2)}%`);
                return;
            }
            
            // 显示结果
            document.getElementById('total-weight').textContent = "100%";
            document.getElementById('total-score').textContent = weightedScore.toFixed(1) + "分";
            
            // 添加动画效果
            const totalRow = document.querySelector('.total-row');
            totalRow.style.backgroundColor = '#e8f5e9';
            setTimeout(() => {
                totalRow.style.transition = 'background-color 1.5s';
                totalRow.style.backgroundColor = '#f5f3fa';
            }, 1000);
        }
        
        // 初始化日期
        document.addEventListener('DOMContentLoaded', function() {
            const now = new Date();
            const year = now.getFullYear();
            const month = now.getMonth() + 1;
            document.getElementById('year-month').textContent = `${year}年${month}月`;
            
            // 为权重和评分单元格添加输入验证
            document.addEventListener('input', function(e) {
                if (e.target.classList.contains('weight') || e.target.classList.contains('score')) {
                    // 简单的输入验证
                    const value = e.target.textContent.trim();
                    if (value && !/^[\d.]*$/.test(value)) {
                        e.target.textContent = value.replace(/[^\d.]/g, '');
                        // 移动光标到末尾
                        const range = document.createRange();
                        const selection = window.getSelection();
                        range.selectNodeContents(e.target);
                        range.collapse(false);
                        selection.removeAllRanges();
                        selection.addRange(range);
                    }
                }
            });
            
            // 添加工作类型提示
            const typeCells = document.querySelectorAll('#work-report tbody td:nth-child(2) .editable');
            typeCells.forEach(cell => {
                if(!cell.textContent.trim()) {
                    cell.textContent = "";
                    cell.style.color = "#999";
                    cell.addEventListener('focus', function() {
                        if(this.textContent === "") {
                            this.textContent = "";
                            this.style.color = "";
                        }
                    });
                    cell.addEventListener('blur', function() {
                        if(!this.textContent.trim()) {
                            this.textContent = "";
                            this.style.color = "#999";
                        }
                    });
                }
            });
        });
    </script>
</body>
</html>